import scrapy

url = 'https://www.cnzj5u.com/list_block.aspx?stid=187&rptid=8'


class Cnzj5uSpider(scrapy.Spider):
    name = "cnzj5u"

    async def start(self):
        yield scrapy.Request(url)

    def parse(self, response):
        lines = response.xpath('//dl[@class="lic_bottom"]//tr')
        next = response.xpath('//a[@id="lkbt_next"]/@href').get()

        for line in lines:
            text = line.xpath('.//a/text()').get()
            print(text)

        if next:
            __EVENTTARGET = next.split("'")[1]
            __EVENTARGUMENT = next.split("'")[3]
            __VIEWSTATE = response.xpath('//input[@name="__VIEWSTATE"]/@value').get()
            __VIEWSTATEGENERATOR = response.xpath('//input[@name="__VIEWSTATEGENERATOR"]/@value').get()
            __EVENTVALIDATION = response.xpath('//input[@name="__EVENTVALIDATION"]/@value').get()
            # print(__EVENTTARGET)
            # print(__EVENTARGUMENT)
            # print(__VIEWSTATE)
            # print(__VIEWSTATEGENERATOR)
            # print(__EVENTVALIDATION)
            yield scrapy.FormRequest(url, formdata={
                '__EVENTARGUMENT': __EVENTARGUMENT,
                '__EVENTTARGET': __EVENTTARGET,
                '__VIEWSTATE': __VIEWSTATE,
                '__VIEWSTATEGENERATOR': __VIEWSTATEGENERATOR,
                '__EVENTVALIDATION': __EVENTVALIDATION
            })
